package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.api.model.vo.request.OrderExpressFeeConfigUpdateVO;
import com.ssy.lingxi.order.api.model.vo.request.OrderScoreConfigUpdateVO;
import com.ssy.lingxi.order.api.model.vo.response.OrderExpressFeeConfigDetailVO;
import com.ssy.lingxi.order.api.model.vo.response.OrderScoreConfigDetailVO;
import com.ssy.lingxi.order.service.base.IBaseCacheService;
import com.ssy.lingxi.order.service.web.IOrderParamConfigService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  @menu 系统能力 -参数配置-[积分相关][运费相关]
 * @author ds
 * @date 2022/2/21
 * @version 2.0.0
 */
@RestController
@RequestMapping("/order/param/config")
public class OrderParamConfigController {
    @Resource
    private IOrderParamConfigService orderConfigService;
    @Resource
    private IBaseCacheService baseCacheService;

    /**
     * 查看-积分抵扣订单
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/score/get", method = RequestMethod.GET)
    public Wrapper<OrderScoreConfigDetailVO> getScoreConfig(@RequestHeader HttpHeaders headers) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return orderConfigService.getScoreConfig(loginUser);
    }

    /**
     * 添加/修改-积分抵扣订单
     * @param headers HttpHeaders信息
     * @param updateVO 接口参数
     * @return 修改结果
     */
    @RequestMapping(value = "/score/update", method = RequestMethod.POST)
    public Wrapper<Void> updateScoreConfig(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderScoreConfigUpdateVO updateVO) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return orderConfigService.updateScoreConfig(loginUser, updateVO);
    }

    /**
     * 查看-满额包邮配置
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/express/fee/get", method = RequestMethod.GET)
    public Wrapper<OrderExpressFeeConfigDetailVO> getExpressFeeConfig(@RequestHeader HttpHeaders headers) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return orderConfigService.getExpressFeeConfig(loginUser);
    }

    /**
     * 添加/修改-满额包邮配置
     * @param headers HttpHeaders信息
     * @param updateVO 接口参数
     * @return 修改结果
     */
    @RequestMapping(value = "/express/fee/update", method = RequestMethod.POST)
    public Wrapper<Void> updateExpressFeeConfig(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderExpressFeeConfigUpdateVO updateVO) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return orderConfigService.updateExpressFeeConfig(loginUser, updateVO);
    }


}

